<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Create Your Project - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/learning.quickstart.create-project.html">Inglês (English)</a></li>
    <li><a href="../pt-br/learning.quickstart.create-project.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.quickstart.intro.html">Zend Framework &amp; MVC Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.quickstart.html">Zend Framework Quick Start</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.quickstart.create-layout.html">Create A Layout</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="learning.quickstart.create-project" class="section"><div class="info"><h1 class="title">Create Your Project</h1></div>
    

    <p class="para">
        In order to create your project, you must first download and extract Zend Framework.
    </p>

    <div class="section" id="learning.quickstart.create-project.install-zf"><div class="info"><h1 class="title">Install Zend Framework</h1></div>
        

        <p class="para">
            The easiest way to get Zend Framework along with a complete <acronym class="acronym">PHP</acronym> stack
            is by installing <a href="http://www.zend.com/en/products/server-ce/downloads" class="link external">&raquo; Zend
                Server</a>. Zend Server has native installers for Mac OSX, Windows, Fedora Core,
            and Ubuntu, as well as a universal installation package compatible with most Linux
            distributions.
        </p>

        <p class="para">
            After you have installed Zend Server, the Framework files may be found
            under <var class="filename">/usr/local/zend/share/ZendFramework</var> on Mac OSX and Linux,
            and <var class="filename">C:\Program Files\Zend\ZendServer\share\ZendFramework</var> on
            Windows. The <b><tt>include_path</tt></b> will already be configured to include
            Zend Framework.
        </p>

        <p class="para">
            Alternately, you can <a href="http://framework.zend.com/download/latest" class="link external">&raquo; Download the
            latest version of Zend Framework</a> and extract the contents; make a note of where
            you have done so.
        </p>

        <p class="para">
            Optionally, you can add the path to the <var class="filename">library/</var> subdirectory of
            the archive to your <var class="filename">php.ini</var>&#039;s <b><tt>include_path</tt></b>
            setting.
        </p>

        <p class="para">
            That&#039;s it! Zend Framework is now installed and ready to use.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.create-project"><div class="info"><h1 class="title">Create Your Project</h1></div>
        

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>zf Command Line Tool</b><br /></span>
            

            <p class="para">
                In your Zend Framework installation is a <var class="filename">bin/</var> subdirectory,
                containing the scripts <var class="filename">zf.sh</var> and <var class="filename">zf.bat</var>
                for Unix-based and Windows-based users, respectively. Make a note of the absolute
                path to this script.
            </p>

            <p class="para">
                Wherever you see references to the command <strong class="command">zf</strong>, please substitute
                the absolute path to the script. On Unix-like systems, you may want to use your
                shell&#039;s alias functionality: <strong class="command">alias
                    zf.sh=path/to/ZendFramework/bin/zf.sh</strong>.
            </p>

            <p class="para">
                If you have problems setting up the <strong class="command">zf</strong> command-line tool, please
                refer to <a href="zend.tool.framework.clitool.html" class="link">the
                    manual</a>.
            </p>
        </p></blockquote>

        <p class="para">
            Open a terminal (in Windows, <strong class="command">Start -&gt; Run</strong>, and then use
            <strong class="command">cmd</strong>). Navigate to a directory where you would like to start a
            project. Then, use the path to the appropriate script, and execute one of the following:
        </p>

        <pre class="programlisting brush: shell">
% zf create project quickstart
</pre>


        <p class="para">
            Running this command will create your basic site structure, including your initial
            controllers and views. The tree looks like the following:
        </p>

        <pre class="programlisting brush: text">
quickstart
|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |   `-- application.ini
|   |-- controllers
|   |   |-- ErrorController.php
|   |   `-- IndexController.php
|   |-- models
|   `-- views
|       |-- helpers
|       `-- scripts
|           |-- error
|           |   `-- error.phtml
|           `-- index
|               `-- index.phtml
|-- library
|-- public
|   |-- .htaccess
|   `-- index.php
`-- tests
    |-- application
    |   `-- bootstrap.php
    |-- library
    |   `-- bootstrap.php
    `-- phpunit.xml
</pre>


        <p class="para">
            At this point, if you haven&#039;t added Zend Framework to your
            <b><tt>include_path</tt></b>, we recommend either copying or symlinking it into
            your <var class="filename">library/</var> directory. In either case, you&#039;ll want to either
            recursively copy or symlink the <var class="filename">library/Zend/</var> directory of your
            Zend Framework installation into the <var class="filename">library/</var> directory of your
            project. On unix-like systems, that would look like one of the following:
        </p>

        <pre class="programlisting brush: shell">
# Symlink:
% cd library; ln -s path/to/ZendFramework/library/Zend .

# Copy:
% cd library; cp -r path/to/ZendFramework/library/Zend .
</pre>


        <p class="para">
            On Windows systems, it may be easiest to do this from the Explorer.
        </p>

        <p class="para">
            Now that the project is created, the main artifacts to begin understanding are the
            bootstrap, configuration, action controllers, and views.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.bootstrap"><div class="info"><h1 class="title">The Bootstrap</h1></div>
        

        <p class="para">
            Your <span class="classname">Bootstrap</span> class defines what resources and components to
            initialize. By default, Zend Framework&#039;s <a href="zend.controller.front.html" class="link">Front
                Controller</a> is initialized, and it uses the
            <var class="filename">application/controllers/</var> as the default directory in which to look
            for action controllers (more on that later). The class looks like the following:
        </p>

        <pre class="programlisting brush: php">
// application/Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}
</pre>


        <p class="para">
            As you can see, not much is necessary to begin with.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.configuration"><div class="info"><h1 class="title">Configuration</h1></div>
        

        <p class="para">
            While Zend Framework is itself configurationless, you often need to configure your
            application. The default configuration is placed in
            <var class="filename">application/configs/application.ini</var>, and contains some basic
            directives for setting your <acronym class="acronym">PHP</acronym> environment (for instance, turning
            error reporting on and off), indicating the path to your bootstrap class (as well as its
            class name), and the path to your action controllers. It looks as follows:
        </p>

        <pre class="programlisting brush: ini">
; application/configs/application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH &quot;/../library&quot;
bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot;
bootstrap.class = &quot;Bootstrap&quot;
appnamespace = &quot;Application&quot;
resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;
resources.frontController.params.displayExceptions = 0

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
</pre>


        <p class="para">
            Several things about this file should be noted. First, when using
            <acronym class="acronym">INI</acronym>-style configuration, you can reference constants directly and
            expand them; <b><tt>APPLICATION_PATH</tt></b> is actually a constant. Additionally
            note that there are several sections defined: production, staging, testing, and
            development. The latter three inherit settings from the &quot;production&quot; environment. This
            is a useful way to organize configuration to ensure that appropriate settings are
            available in each stage of application development.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.action-controllers"><div class="info"><h1 class="title">Action Controllers</h1></div>
        

        <p class="para">
            Your application&#039;s <em class="emphasis">action controllers</em> contain your application
            workflow, and do the work of mapping your requests to the appropriate models and views.
        </p>

        <p class="para">
            An action controller should have one or more methods ending in &quot;Action&quot;; these methods
            may then be requested via the web. By default, Zend Framework URLs follow the schema
            <b><tt>/controller/action</tt></b>, where &quot;controller&quot; maps to the action
            controller name (minus the &quot;Controller&quot; suffix) and &quot;action&quot; maps to an action method
            (minus the &quot;Action&quot; suffix).
        </p>

        <p class="para">
            Typically, you always need an <span class="classname">IndexController</span>, which is a
            fallback controller and which also serves the home page of the site, and an
            <span class="classname">ErrorController</span>, which is used to indicate things such as
            <acronym class="acronym">HTTP</acronym> 404 errors (controller or action not found) and
            <acronym class="acronym">HTTP</acronym> 500 errors (application errors).
        </p>

        <p class="para">
            The default <span class="classname">IndexController</span> is as follows:
        </p>

        <pre class="programlisting brush: php">
// application/controllers/IndexController.php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }
}
</pre>


        <p class="para">
            And the default <span class="classname">ErrorController</span> is as follows:
        </p>

        <pre class="programlisting brush: php">
// application/controllers/ErrorController.php

class ErrorController extends Zend_Controller_Action
{

    public function errorAction()
    {
        $errors = $this-&gt;_getParam(&#039;error_handler&#039;);

        switch ($errors-&gt;type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this-&gt;getResponse()-&gt;setHttpResponseCode(404);
                $this-&gt;view-&gt;message = &#039;Page not found&#039;;
                break;
            default:
                // application error
                $this-&gt;getResponse()-&gt;setHttpResponseCode(500);
                $this-&gt;view-&gt;message = &#039;Application error&#039;;
                break;
        }

        $this-&gt;view-&gt;exception = $errors-&gt;exception;
        $this-&gt;view-&gt;request   = $errors-&gt;request;
    }
}
</pre>


        <p class="para">
            You&#039;ll note that (1) the <span class="classname">IndexController</span> contains no real code,
            and (2) the <span class="classname">ErrorController</span> makes reference to a &quot;view&quot; property.
            That leads nicely into our next subject.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.views"><div class="info"><h1 class="title">Views</h1></div>
        

        <p class="para">
            Views in Zend Framework are written in plain old <acronym class="acronym">PHP</acronym>. View scripts
            are placed in <var class="filename">application/views/scripts/</var>, where they are further
            categorized using the controller names. In our case, we have an
            <span class="classname">IndexController</span> and an <span class="classname">ErrorController</span>,
            and thus we have corresponding <var class="filename">index/</var> and
            <var class="filename">error/</var> subdirectories within our view scripts directory. Within
            these subdirectories, you will then find and create view scripts that correspond to each
            controller action exposed; in the default case, we thus have the view scripts
            <var class="filename">index/index.phtml</var> and <var class="filename">error/error.phtml</var>.
        </p>

        <p class="para">
            View scripts may contain any markup you want, and use the <em class="emphasis">&lt;?php</em>
            opening tag and <em class="emphasis">?&gt;</em> closing tag to insert <acronym class="acronym">PHP</acronym>
            directives.
        </p>

        <p class="para">
            The following is what we install by default for the
            <var class="filename">index/index.phtml</var> view script:
        </p>

        <pre class="programlisting brush: php">
&lt;!-- application/views/scripts/index/index.phtml --&gt;
&lt;style&gt;

    a:link,
    a:visited
    {
        color: #0398CA;
    }

    span#zf-name
    {
        color: #91BE3F;
    }

    div#welcome
    {
        color: #FFFFFF;
        background-image: url(http://framework.zend.com/images/bkg_header.jpg);
        width:  600px;
        height: 400px;
        border: 2px solid #444444;
        overflow: hidden;
        text-align: center;
    }

    div#more-information
    {
        background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
        height: 100%;
    }

&lt;/style&gt;
&lt;div id=&quot;welcome&quot;&gt;
    &lt;h1&gt;Welcome to the &lt;span id=&quot;zf-name&quot;&gt;Zend Framework!&lt;/span&gt;&lt;h1 /&gt;
    &lt;h3&gt;This is your project&#039;s main page&lt;h3 /&gt;
    &lt;div id=&quot;more-information&quot;&gt;
        &lt;p&gt;
            &lt;img src=&quot;http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png&quot; /&gt;
        &lt;/p&gt;

        &lt;p&gt;
            Helpful Links: &lt;br /&gt;
            &lt;a href=&quot;http://framework.zend.com/&quot;&gt;Zend Framework Website&lt;/a&gt; |
            &lt;a href=&quot;http://framework.zend.com/manual/en/&quot;&gt;Zend Framework
                Manual&lt;/a&gt;
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre>


        <p class="para">
            The <var class="filename">error/error.phtml</var> view script is slightly more interesting as
            it uses some <acronym class="acronym">PHP</acronym> conditionals:
        </p>

        <pre class="programlisting brush: php">
&lt;!-- application/views/scripts/error/error.phtml --&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
  &lt;title&gt;Zend Framework Default Application&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h1&gt;An error occurred&lt;/h1&gt;
  &lt;h2&gt;&lt;?php echo $this-&gt;message ?&gt;&lt;/h2&gt;

  &lt;?php if (&#039;development&#039; == $this-&gt;env): ?&gt;

  &lt;h3&gt;Exception information:&lt;/h3&gt;
  &lt;p&gt;
      &lt;b&gt;Message:&lt;/b&gt; &lt;?php echo $this-&gt;exception-&gt;getMessage() ?&gt;
  &lt;/p&gt;

  &lt;h3&gt;Stack trace:&lt;/h3&gt;
  &lt;pre&gt;&lt;?php echo $this-&gt;exception-&gt;getTraceAsString() ?&gt;
  &lt;/pre&gt;

  &lt;h3&gt;Request Parameters:&lt;/h3&gt;
  &lt;pre&gt;&lt;?php echo var_export($this-&gt;request-&gt;getParams(), 1) ?&gt;
  &lt;/pre&gt;
  &lt;?php endif ?&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>

    </div>

    <div class="section" id="learning.quickstart.create-project.vhost"><div class="info"><h1 class="title">Create a virtual host</h1></div>
        

        <p class="para">
            For purposes of this quick start, we will assume you are using the <a href="http://httpd.apache.org/" class="link external">&raquo; Apache web server</a>. Zend Framework works
            perfectly well with other web servers -- including Microsoft Internet Information
            Server, lighttpd, nginx, and more -- but most developers should be famililar with Apache
            at the minimum, and it provides an easy introduction to Zend Framework&#039;s directory
            structure and rewrite capabilities.
        </p>

        <p class="para">
            To create your vhost, you need to know the location of your
            <var class="filename">httpd.conf</var> file, and potentially where other configuration files
            are located. Some common locations:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <var class="filename">/etc/httpd/httpd.conf</var> (Fedora, RHEL, and others)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <var class="filename">/etc/apache2/httpd.conf</var> (Debian, Ubuntu, and others)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <var class="filename">/usr/local/zend/etc/httpd.conf</var> (Zend Server on *nix
                    machines)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <var class="filename">C:\Program Files\Zend\Apache2\conf</var> (Zend Server on Windows
                    machines)
                </p>
            </li>
        </ul>

        <p class="para">
            Within your <var class="filename">httpd.conf</var> (or <var class="filename">httpd-vhosts.conf</var>
            on some systems), you will need to do two things. First, ensure that the
            <var class="varname">NameVirtualHost</var> is defined; typically, you will set it to a value of
            &quot;*:80&quot;. Second, define a virtual host:
        </p>

        <pre class="programlisting brush: apache">
&lt;VirtualHost *:80&gt;
    ServerName quickstart.local
    DocumentRoot /path/to/quickstart/public

    SetEnv APPLICATION_ENV &quot;development&quot;

    &lt;Directory /path/to/quickstart/public&gt;
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>


        <p class="para">
            There are several things to note. First, note that the <var class="varname">DocumentRoot</var>
            setting specifies the <var class="filename">public</var> subdirectory of our project; this
            means that only files under that directory can ever be served directly by the server.
            Second, note the <var class="varname">AllowOverride</var>, <var class="varname">Order</var>, and
            <var class="varname">Allow</var> directives; these are to allow us to use
            <var class="filename">htacess</var> files within our project. During development, this is a
            good practice, as it prevents the need to constantly restart the web server as you make
            changes to your site directives; however, in production, you should likely push the
            content of your <var class="filename">htaccess</var> file into your server configuration and
            disable this. Third, note the <var class="varname">SetEnv</var> directive. What we are doing
            here is setting an environment variable for your virtual host; this variable will be
            picked up in the <var class="filename">index.php</var> and used to set the
            <b><tt>APPLICATION_ENV</tt></b> constant for our Zend Framework application. In
            production, you can omit this directive (in which case it will default to the value
            &quot;production&quot;) or set it explicitly to &quot;production&quot;.
        </p>

        <p class="para">
            Finally, you will need to add an entry in your <var class="filename">hosts</var> file
            corresponding to the value you place in your <var class="varname">ServerName</var> directive. On
            *nix-like systems, this is usually <var class="filename">/etc/hosts</var>; on Windows, you&#039;ll
            typically find it in <var class="filename">C:\WINDOWS\system32\drivers\etc</var>. Regardless of
            the system, the entry will look like the following:
        </p>

        <pre class="programlisting brush: text">
127.0.0.1 quickstart.local
</pre>


        <p class="para">
            Start your webserver (or restart it), and you should be ready to go.
        </p>
    </div>

    <div class="section" id="learning.quickstart.create-project.checkpoint"><div class="info"><h1 class="title">Checkpoint</h1></div>
        

        <p class="para">
            At this point, you should be able to fire up your initial Zend Framework application.
            Point your browser to the server name you configured in the previous section; you should
            be able to see a welcome page at this point.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.quickstart.intro.html">Zend Framework &amp; MVC Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.quickstart.html">Zend Framework Quick Start</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.quickstart.create-layout.html">Create A Layout</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="learning.html">Learning Zend Framework</a></li>
  <li class="header up"><a href="learning.quickstart.html">Zend Framework Quick Start</a></li>
  <li><a href="learning.quickstart.intro.html">Zend Framework &amp; MVC Introduction</a></li>
  <li class="active"><a href="learning.quickstart.create-project.html">Create Your Project</a></li>
  <li><a href="learning.quickstart.create-layout.html">Create A Layout</a></li>
  <li><a href="learning.quickstart.create-model.html">Create a Model and Database Table</a></li>
  <li><a href="learning.quickstart.create-form.html">Create A Form</a></li>
  <li><a href="learning.quickstart.conclusion.html">Congratulations!</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>